package com.jp.fm.service;

import static org.easymock.EasyMock.expect;
import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.jp.fm.EasyMockParent;
import com.jp.fm.dao.BudgetDao;
import com.jp.fm.dao.TransactionDao;
import com.jp.fm.data.Budget;
import com.jp.fm.data.Category;
import com.jp.fm.data.Transaction;

public class BudgetServiceTest extends EasyMockParent {

	private BudgetService budgetService = null;

	private TransactionService mockTransactionService = null;
	private TransactionDao mockTransactionDao = null;
	private BudgetDao mockBudgetDao = null;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
		super.setUp();

		budgetService = new BudgetService();
	}

	@After
	public void tearDown() throws Exception {
		super.tearDown();
	}

	@Test
	public final void testFindBudgetList() {

		Date startDate = new Date();
		Date endDate = new Date();

		List<String> alerts = new ArrayList<String>();

		List<Transaction> list = new ArrayList<Transaction>();
		list.add(new Transaction(null, null, null, null, null, null, null,
				false, null));

		Category cat = new Category(null, "category");

		List<Budget> budgets = new ArrayList<Budget>();
		budgets.add(new Budget(null, null, Float.valueOf("100.00"), null, null,
				cat));

		expect(mockBudgetDao.findByDate(startDate)).andReturn(budgets);
		expect(
				mockTransactionDao.findByAny(cat, startDate, endDate, null,
						null, null)).andReturn(list);
		expect(mockTransactionService.calculateTransactionsTotal(list, cat))
				.andReturn(Float.valueOf("200.00"));

		replayMocks();

		budgetService.setBudgetDao(mockBudgetDao);
		budgetService.setTransactionDao(mockTransactionDao);
		budgetService.setTransactionService(mockTransactionService);
		budgetService.findBudgetList(startDate, endDate, alerts);

		assertEquals(1, alerts.size());
	}
}
